package com.zt.student.controller;

import com.zt.common.pojo.common.JsonResult;
import com.zt.common.pojo.exam.Exam;
import com.zt.student.dto.ExamAnswerDTO;
import com.zt.student.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * description:
 * author:zt
 * date:2022-02-15
 */
@RestController
@CrossOrigin
@RequestMapping("exam")
@Api("考试模块")
public class ExamController {

    @Autowired
    private ExamService examService;

    @GetMapping("get/{classId}")
    @ApiOperation("根据班级id获取所有考试")
    public JsonResult<List<Exam>> getByClassId(HttpServletRequest request, @PathVariable int classId){
        return JsonResult.success(examService.getExamByClassId(request,classId));
    }

    @GetMapping("getDetail/{examId}")
    @ApiOperation("根据考试id获取学生试题及回答")
    public JsonResult<List<ExamAnswerDTO>> getQuestionAndAnswer(HttpServletRequest request,@PathVariable int examId){
        List<ExamAnswerDTO> questionAndAnswer = examService.getQuestionAndAnswer(request, examId);
        return JsonResult.success(questionAndAnswer);
    }
}
